package com.q.tqb.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.q.tqb.R;
import com.q.tqb.model.MineCardInfo;
import com.q.tqb.util.StringUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CardAdapter extends RecyclerView.Adapter<CardAdapter.ViewHolder> {

    private ArrayList<MineCardInfo> mRedPersonDatas;
    private Context mContext;


    public CardAdapter(Context context, ArrayList<MineCardInfo> mRedPersonDatas) {
        this.mRedPersonDatas = mRedPersonDatas;
        this.mContext = context;

    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_card, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        MineCardInfo getRedPersonData = mRedPersonDatas.get(position);
        holder.mTvBankName.setText(getRedPersonData.getBank_name());

        holder.mTvCardNo.setText(StringUtil.formatCard(getRedPersonData.getBank_account()));

        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                mOnItemClickListener.onClick(position);
                return false;
            }
        });


    }

    @Override
    public int getItemCount() {
        return mRedPersonDatas.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.image)
        ImageView mImage;
        @BindView(R.id.tv_bank_name)
        TextView mTvBankName;
        @BindView(R.id.tv_card_no)
        TextView mTvCardNo;
        @BindView(R.id.ll_card)
        LinearLayout mLlCard;

        ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClickListener {
        void onClick(int position);
    }

    private OnItemClickListener mOnItemClickListener;


    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

}